﻿@using SCMS.Resource
@model SCMS.UI.Models.WRFRequest
@{AjaxOptions ajaxOpts = new AjaxOptions
  {

      UpdateTargetId = "popup-page",
      LoadingElementId = "popup-loading",
      HttpMethod = "Post",
      Url = Url.Action("LoadWRFItem"),
      OnBegin = "ShowDialogue('" + Resources.WRForm_LoadWRF_InventoryItems + "')",
      OnSuccess = "document.getElementById('txtqtyordered').value='';CenterPopup"
  };}
<script src="@Url.Content("~/Scripts/js/jquery-1.7.2.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<div class="partialViewCard">
    <div class="partialViewCardHeader">
        <h3>
            @Resources.WRForm_LoadWRF_WRO</h3>
    </div>
    <br />
    @using (Ajax.BeginForm(null, null, ajaxOpts, new { @class = "form", @id = "frmwrn" }))
    {
        @Html.ValidationSummary(true)
        <table width="98%" align="center" cellpadding="0">
            <tr>
                <th align="center" width="33.3%">
                    @Resources.WRForm_LoadWRF_WRFNo
                </th>
                <th align="center" width="33.3%">
                    @Resources.WRForm_LoadWRF_RequestDate
                </th>
                <th align="center" width="33.3%">
                    @Resources.WRForm_LoadWRF_Requestor
                </th>
            </tr>
            <tr>
                <td align="center">
                    @Html.TextBoxFor(m => m.EntityWHouseRelease.RefNumber, new { @readonly = "readonly" })
                </td>
                <td align="center">
                    @Html.EditorFor(m => m.EntityWHouseRelease.RequestDate)
                    @Html.ValidationMessageFor(m => m.EntityWHouseRelease.RequestDate)
                </td>
                <td align="center">
                    @ViewBag.RequestorName
                    @*@Html.DropDownListFor(x => x.EntityWHouseRelease.RequestorId, Model.Staff, "- please select -")
                    @Html.ValidationMessageFor(x => x.EntityWHouseRelease.RequestorId)*@
                </td>
            </tr>
            <tr>
                <th align="center">
                    @Resources.WRForm_LoadWRF_Recipient
                </th>
                <th align="center">
                    @Resources.WRForm_LoadWRF_Tobeapprovedby
                </th>
                <th align="center">
                    From Warehouse
                </th>
            </tr>
            <tr>
                <td align="center">
                    @Html.DropDownListFor(x => x.EntityWHouseRelease.ReceivedBy, Model.Staff, Resources.Global_String_PleaseSelect)
                    @Html.ValidationMessageFor(x => x.EntityWHouseRelease.ReceivedBy, Resources.Global_String_Required)
                </td>
                <td align="center">
                    @Html.DropDownListFor(x => x.EntityWHouseRelease.ApprovedBy, Model.ApproversList, Resources.Global_String_PleaseSelect)
                    @Html.ValidationMessageFor(x => x.EntityWHouseRelease.ApprovedBy, Resources.Global_String_Required)
                </td>
                <td align="center">
                    @Html.DropDownListFor(x => x.EntityWHouseRelease.WareHouseId, Model.Warehouses, Resources.Global_String_PleaseSelect)
                    @Html.ValidationMessageFor(x => x.EntityWHouseRelease.WareHouseId, Resources.Global_String_Required)
                </td>
            </tr>
            <tr>
                <td align="left">
                    &nbsp;
                    <input class="btn green" id="btnsave" type="submit" value=" @Resources.Global_String_AddItem " />
                </td>
                <td>
                </td>
            </tr>
        </table>
    }
    @if (Model.WRNItemList.Count() <= 0 & Model.EntityWHouseRelease.Id.IsNotEmpty())
    { <div style="width: 98%;">
        &nbsp;&nbsp;&nbsp;
        @Ajax.ActionLink(Resources.Global_String_AddItem, "NewItem", new { wrnId = Model.EntityWHouseRelease.Id }, new AjaxOptions
       {
           OnBegin = string.Format("ShowDialogue('{0}')", Resources.Global_String_AddItem),
           UpdateTargetId = "popup-page",
           LoadingElementId = "popup-loading",
           OnSuccess = "CenterPopup"
       })
    </div>
    }
    @if (Model.WRNItemList.Count() > 0)
    {
        <hr />
         
        <div style="width: 98%;">
            &nbsp;&nbsp;&nbsp;
            @Ajax.ActionLink(Resources.Global_String_AddItem, "NewItem", new { wrnId = Model.EntityWHouseRelease.Id }, new AjaxOptions
       {
           OnBegin = string.Format("ShowDialogue('{0}')", Resources.Global_String_AddItem),
           UpdateTargetId = "popup-page",
           LoadingElementId = "popup-loading",
           OnSuccess = "CenterPopup"
       })
        </div>
        <table width="98%" align="center" class="cardTable" cellspacing="0" cellpadding="0"
            border="1">
            <tr class="gridheader">
                <th>
                    @Resources.WRForm_LoadWRF_ItemGoodsDescription
                </th>
                <th>
                    @Resources.Global_String_UnitMessure
                </th>
                <th>
                    @Resources.Global_String_SerialNo
                </th>
                <th>
                    @Resources.Global_String_AssetNo
                </th>
                <th>
                    @Resources.Global_String_Quantity
                </th>
                <th>
                    @Resources.Global_String_Comments
                </th>
                <th>
                    @Resources.Global_String_Manage
                </th>
            </tr>
            @{ string itemName, serialNo, assetNo; }
            @foreach (var item in Model.WRNItemList)
            {
                if (item.Inventory.Item.ItemCategory.CategoryCode == "C")
                {
                    itemName = item.Inventory.Item.Name;
                    serialNo = item.Inventory.Item.SerialNumber;
                    assetNo = Resources.Global_String_NA;
                }
                else
                {
                    itemName = item.Asset.Name;
                    serialNo = item.Asset.SerialNumber;
                    assetNo = item.Asset.AssetNumber;
                }
                    
                <tr class="gridodd">
                    <td>
                        @itemName
                    </td>
                    <td align="center">
                        @item.Inventory.Item.UnitOfMeasure.Code
                    </td>
                    <td align="center">
                        @serialNo
                    </td>
                    <td align="left">
                        @assetNo
                    </td>
                    <td align="center">
                        @item.Quantity
                    </td>
                    <td align="left">
                        @item.Comments
                    </td>
                    <td>
                        @*@Ajax.ActionLink("Edit", "EditItem", new { @wrnItmId = item.Id }, new AjaxOptions
                   {
                       OnBegin = "ShowDialogue('Edit WRN Item')",
                       UpdateTargetId = "popup-page",
                       LoadingElementId = "popup-loading",
                       OnSuccess = "CenterPopupPO"

                   })*@ &nbsp;&nbsp;
                        @Ajax.ActionLink(Resources.Global_String_Remove, "DeleteWRNItem", new { @wrnId = Model.EntityWHouseRelease.Id, @wrnItmId = item.Id }, new AjaxOptions
                   {
                       UpdateTargetId = "wrfDiv",
                       LoadingElementId = "loading",
                       Confirm = Resources.WRForm_LoadWRF_confirmDeleteWRItem,
                       OnSuccess = "hidebutton('btnsave');usermsgg"
                   })
                    </td>
                </tr>
            }
        </table>
        <input type="hidden" id="actionStatus" value="@ViewBag.Response" />
        <input type="hidden" id="statusMsg" value="@ViewBag.msg" />
        <br /> <div style="width: 98%;">
            &nbsp;&nbsp;&nbsp;
            <input type="button" class="btn green" value="  @Resources.Global_String_SubmitForApproval  " onclick="sendRequest('SubmitWRN/@Model.EntityWHouseRelease.Id', 'wrfDiv', 'loading'); document.getElementById('wrfItemDiv').innerHTML='';initSorter();sorter.size(50);" />
        </div>
        <br />
    }
</div>
